package com.eightywork.life.widget;


import com.eightywork.life.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

/**
 * ͨ�õ�ListView footer�����б�ײ���ʾ��ݼ��أ�δ���ص����ʱ��ʾ���¼��أ������ʱ��ʾ������ݡ�����ȡ�
 * 
 * @author xiaoxh
 * @version 1.00
 */
public class FooterView {
	/**  */
	private LinearLayout rlFooterLayout;
	/**  */
	private LinearLayout llFooterLoadingLayout;
	/**  */
//	private ProgressBar pbFooterLoadingProgressBar;
	/**  */
//	private TextView tvFooterLoadingText;
	/**  */
	private LinearLayout llFooterReloadLayout;
	/**  */
//	private TextView tvFooterReloadText;
	/**  */
	private Button btnFooterReload;
	/**  */
	private LinearLayout llFooterNodataLayout;
	/**  */
//	private TextView tvFooterNodataText;

	/**
	 * ��ʼ��View
	 * @param ctx
	 */
	public FooterView(Context ctx) {
		this.rlFooterLayout = (LinearLayout) LayoutInflater.from(ctx).inflate(R.layout.footer_load_progress_tip, null);
		llFooterLoadingLayout = (LinearLayout) rlFooterLayout.findViewById(R.id.footer_loading_layout );
//		pbFooterLoadingProgressBar = (ProgressBar) rlFooterLayout.findViewById( R.id.footer_loading_progress_bar );
//		tvFooterLoadingText = (TextView) rlFooterLayout.findViewById( R.id.footer_loading_text );
		llFooterReloadLayout = (LinearLayout) rlFooterLayout.findViewById( R.id.footer_reload_layout );
//		tvFooterReloadText = (TextView) rlFooterLayout.findViewById( R.id.footer_reload_text );
		btnFooterReload = (Button) rlFooterLayout.findViewById( R.id.footer_reload );
		llFooterNodataLayout = (LinearLayout) rlFooterLayout.findViewById( R.id.footer_nodata_layout );
//		tvFooterNodataText = (TextView) rlFooterLayout.findViewById( R.id.footer_nodata_text );
	}
	
	/**
	 * ��ʼ��View
	 * @param ctx
	 */
	public FooterView(Activity app, boolean activity) {
		if(activity){
			this.rlFooterLayout = (LinearLayout) app.findViewById(R.id.footer_root_layout);
		}
		else{
			this.rlFooterLayout = (LinearLayout) LayoutInflater.from(app).inflate(R.layout.footer_load_progress_tip, null);
		}
			
		llFooterLoadingLayout = (LinearLayout) rlFooterLayout.findViewById( R.id.footer_loading_layout );
//		pbFooterLoadingProgressBar = (ProgressBar) rlFooterLayout.findViewById( R.id.footer_loading_progress_bar );
//		tvFooterLoadingText = (TextView) rlFooterLayout.findViewById( R.id.footer_loading_text );
		llFooterReloadLayout = (LinearLayout) rlFooterLayout.findViewById( R.id.footer_reload_layout );
//		tvFooterReloadText = (TextView) rlFooterLayout.findViewById( R.id.footer_reload_text );
		btnFooterReload = (Button) rlFooterLayout.findViewById( R.id.footer_reload );
		llFooterNodataLayout = (LinearLayout) rlFooterLayout.findViewById( R.id.footer_nodata_layout );
//		tvFooterNodataText = (TextView) rlFooterLayout.findViewById( R.id.footer_nodata_text );
		hideAll();
	}
	
	/**
	 * ��ʼ��View
	 * @param ctx
	 */
	public FooterView(View view) {
		this.rlFooterLayout = (LinearLayout) view.findViewById(R.id.footer_root_layout);
		llFooterLoadingLayout = (LinearLayout) rlFooterLayout.findViewById( R.id.footer_loading_layout );
//		pbFooterLoadingProgressBar = (ProgressBar) rlFooterLayout.findViewById( R.id.footer_loading_progress_bar );
//		tvFooterLoadingText = (TextView) rlFooterLayout.findViewById( R.id.footer_loading_text );
		llFooterReloadLayout = (LinearLayout) rlFooterLayout.findViewById( R.id.footer_reload_layout );
//		tvFooterReloadText = (TextView) rlFooterLayout.findViewById( R.id.footer_reload_text );
		btnFooterReload = (Button) rlFooterLayout.findViewById( R.id.footer_reload );
		llFooterNodataLayout = (LinearLayout) rlFooterLayout.findViewById( R.id.footer_nodata_layout );
//		tvFooterNodataText = (TextView) rlFooterLayout.findViewById( R.id.footer_nodata_text );
		hideAll();
	}

	/**
	 * ���صײ�������ʾ
	 */
	public void hideAll() {
		this.rlFooterLayout.setVisibility(View.GONE);
		llFooterLoadingLayout.setVisibility(View.GONE);
		llFooterReloadLayout.setVisibility(View.GONE);
		llFooterNodataLayout.setVisibility(View.GONE);
		rlFooterLayout.invalidate();
	}

	/**
	 * ��ʾ���¼��ذ�ť����ʾ
	 */
	public void showReload() {  //���¼���
		this.rlFooterLayout.setVisibility(View.VISIBLE);
		llFooterLoadingLayout.setVisibility(View.GONE);
		llFooterReloadLayout.setVisibility(View.VISIBLE);
		llFooterNodataLayout.setVisibility(View.GONE);
		rlFooterLayout.invalidate();
	}

	/**
	 * ��ʾ��ݼ����еĽ�Ⱥ���ʾ
	 */
	public void showLoading() {
		this.rlFooterLayout.setVisibility(View.VISIBLE);
		llFooterLoadingLayout.setVisibility(View.VISIBLE);
		llFooterReloadLayout.setVisibility(View.GONE);
		llFooterNodataLayout.setVisibility(View.GONE);
		rlFooterLayout.invalidate();
	}
	
	/**
	 * ��ʾ����ݵ���ʾ
	 */
	public void showNoData(){
		this.rlFooterLayout.setVisibility(View.VISIBLE);
		llFooterLoadingLayout.setVisibility(View.GONE);
		llFooterReloadLayout.setVisibility(View.GONE);
		llFooterNodataLayout.setVisibility(View.VISIBLE);
		rlFooterLayout.invalidate();
	}
	
	/**
	 * ���صײ�����Layout���ֵ�View��RelativeLayout
	 */
	public LinearLayout getFooter(){
		return this.rlFooterLayout;
	}
	
	/** �������¼��ذ�ť���¼� */
	public void setReloadButtonListener(View.OnClickListener listener){
		this.btnFooterReload.setOnClickListener(listener);
	}
}
